package com.trace.communication;

/**
 * Created by denglw on 2020/1/6.<br/>
 * Desc: 等待/通知机制
 */
public class WaitNotify {

    public static void main(String[] args) {
        final Object lock = new Object();

        new Thread(() -> {
            synchronized (lock) {
                System.out.println("start");
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("end");
            }
        }).start();

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(() -> {
            synchronized (lock) {
                System.out.println("notify");
                lock.notify();
            }
        }).start();
    }

}
